package com.dj.mingkong.portal.biz.controller.music;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dj.mingkong.common.annotation.RequestLimit;
import com.dj.mingkong.common.infrastructure.base.dto.page.PageVo;
import com.dj.mingkong.common.infrastructure.base.dto.rest.RestResponse;
import com.dj.mingkong.common.microservice.UserContext;
import com.dj.mingkong.common.util.AssertUtils;
import com.dj.mingkong.common.util.SmartBeanCopy;
import com.dj.mingkong.portal.biz.controller.music.vo.request.BoxMusicAddVo;
import com.dj.mingkong.portal.biz.controller.music.vo.request.BoxMusicCancelVo;
import com.dj.mingkong.portal.biz.controller.music.vo.request.BoxMusicQueryVo;
import com.dj.mingkong.portal.biz.controller.music.vo.response.BoxMusicVo;
import com.dj.mingkong.portal.biz.service.music.BoxMusicService;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * 收藏音乐管理
 *
 * @author zenglonghui
 * @date: 2022/9/1 22:36
 */
@RestController
@RequestMapping("/box/music")
public class BoxMusicController {
    @Resource
    private BoxMusicService boxMusicService;

    /**
     * 新增音乐盒音乐
     *
     * @param addVo 实例对象
     * @return 是否成功，true-成功，false-失败
     */
    @PostMapping("/add")
    @RequestLimit(count = 10)
    public RestResponse<Boolean> add(@RequestBody @Validated BoxMusicAddVo addVo) {
        boxMusicService.add(addVo);
        return RestResponse.buildSuccess();
    }

    /**
     * 音乐收藏列表查询
     *
     * @param queryVo {}
     * @return BoxMusicVo
     */
    @PostMapping("/pageByVo")
    public RestResponse<PageVo<BoxMusicVo>> pageByVo(@RequestBody BoxMusicQueryVo queryVo) {
        AssertUtils.checkQueryPageVo(queryVo);
        queryVo.setUserId(UserContext.getUserId());
        final Page<BoxMusicVo> boxMusicVoPage = boxMusicService.pageByVo(queryVo);
        final PageVo<BoxMusicVo> pageVo = SmartBeanCopy.copyPageVo(boxMusicVoPage, BoxMusicVo.class);
        return RestResponse.success(pageVo);
    }

    /**
     * 取消收藏
     *
     * @param cancelVo {}
     * @return Boolean
     */
    @PostMapping("/cancel")
    @RequestLimit(count = 5)
    public RestResponse<Boolean> cancel(@RequestBody @Validated BoxMusicCancelVo cancelVo) {
        boxMusicService.cancel(cancelVo);
        return RestResponse.buildSuccess();
    }
}
